package com.rabbit.controller;

import com.github.pagehelper.PageInfo;
import com.rabbit.annotation.Log;
import com.rabbit.constant.OperType;
import com.rabbit.service.OperLogService;
import com.rabbit.util.ResultGenUtil;
import com.rabbit.vo.ResultVO;
import com.rabbit.vo.req.OperLogReq;
import com.rabbit.vo.res.OperLogRes;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <h1>操作日志管理</h1>
 *
 * @author zjw
 * @date 2022/1/21 10:36
 */
@RestController
@RequestMapping("/operLog")
public class OperLogController {

    @Resource
    private OperLogService operLogService;

    /**
     * 操作日志列表
     */
    @PostMapping("/list")
    public ResultVO<Object> list(@RequestBody OperLogReq operLogReq) {
        PageInfo<OperLogRes> pageInfo = operLogService.queryOperLogList(operLogReq);
        return ResultGenUtil.genSuccess(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 清空操作日志
     */
    @PostMapping("/truncate")
    @Log(name = "操作日志管理", type = OperType.TRUNCATE)
    public ResultVO<Object> truncate() {
        operLogService.truncateOperLog();
        return ResultGenUtil.genSuccess();
    }

    /**
     * 批量删除操作日志
     */
    @PostMapping("/batchDelete")
    @Log(name = "操作日志管理", type = OperType.DELETE)
    public ResultVO<Object> batchDelete(@Validated @RequestBody OperLogReq operLogReq) {
        return ResultGenUtil.genSuccess(operLogService.batchDelete(operLogReq));
    }

    /**
     * 查看操作日志详细信息
     */
    @GetMapping("/queryDetail")
    public ResultVO<Object> queryDetail(@RequestParam Long operId) {
        return ResultGenUtil.genSuccess(operLogService.queryDetail(operId));
    }
}
